/**
 * 
 */
package ua.kpi.javatrainee6.model.people;

import ua.kpi.javatrainee6.model.assessment.Assessment;
import ua.kpi.javatrainee6.model.assessment.Mark;
import ua.kpi.javatrainee6.model.curriculum.*;
import ua.kpi.javatrainee6.model.departments.*;

/**
 * Professor entity, contains groups and univer reference
 * Provides next functionality: you can view responsibilities, your own curriculum and
 * all groups, you can assess student and calculate your salary, view your evaluation
 */
public final class Professor extends Person implements CurriculumPrintable, Evaluable {
	
	private static final double BASIC_SALARY_FOR_GROUP = 1000.0;
	private University univer;
	private Groups groups;
	
	/** 
	 * Optional constructor, used now for automatic data generation, for more detailed description
	 * look in Person class
	 * @param univer - univer reference, for viewing curriculum
	 */
	public Professor(University univer) {
		super();
		this.univer = univer;
	}
	
	/**
	 * Forming groups, responsibility of UniversityAdministrator
	 * @param groups
	 */
	public void setGroups(Groups groups) {
		this.groups = groups;
	}
	
	/**
	 * Curriculum for particular professor, implementation of CurriculumPrintable method
	 */
	public void viewCurriculum() {
		Curriculum curriculum = univer.getCurriculum();
		System.out.println("Curriculum for professor - " + getShortDescription());
		curriculum.printCurriculum(this);
	}
	
	/**
	 * Evaluation for professor, implementation from Evaluable interface
	 * depends on average score for all professor's groups
	 */
	public void evaluateAsBadOrGood() {
		System.out.printf("Results of evaluation for professor %s:\n", getShortDescription());
		double sum = 0.0;
		for (Group group : groups) {
			sum += group.calculateAverage();
		}
		double compareScore = sum / groups.size();
		if (compareScore >= GOOD_SCORE) {
			System.out.println("Thank you, you are good professor");
		} else if (compareScore <= BAD_SCORE) {
			System.out.println("Sorry, you are very bad professor");
		} else {
			System.out.println("You are in the middle, not good, not bad");
		}
	}
	
	/**
	 * Implementing abstract method from Person class, viewing all abilities
	 */
	public void viewResponsibilities() {
		System.out.println("YOUR RESPONSIBILITIES");
		System.out.println("As professor you can:\n1. You can view your curriculum and " +
				           "general information about university\n" +
				           "2. Also you can create assessment for student");
	}
	
	/**
	 * Viewing all groups for Professor
	 */
	public void viewAllGroups() {
		System.out.println("All groups for professor " + getShortDescription());
		for (Group group : groups) {
			System.out.println(group.getTitle());
		}
	}
	
	/**
	 * calculating salary for professor, depends on quantity of groups
	 */
	public double calculateSalary() {
		return BASIC_SALARY_FOR_GROUP * groups.size();
	}
	
	@Override
	public String toString() {
		return String.format("Information about professor:\nPersonal info:\n%s\nUniversity: %s\n", 
				             super.toString(), univer);		        
	}
	
	@Override 
	public boolean equals(Object otherObject) {
		if (! super.equals(otherObject)) {
			return false;
		}
		Professor other = (Professor) otherObject;
		if (univer.equals(other.univer)) {
			return true;
		} else {
			return false;
		}
	}
	
	/**
	 * Assessment for students, now all students are assesses with EXCELLENT mark
	 * Will be deleted in later versions - when files or databases with data will be added...
	 * @param subject - subject to assess
	 * @param student - student to assess
	 */
	public void performAssessment(Student student, Subject subject) {
		Assessment assessment = new Assessment(subject, Mark.EXCELLENT);
		student.getMarks().put(assessment);
	}
}

